﻿using Prism.DryIoc;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Services.Dialogs;
using System.Configuration;
using System.Data;
using System.Windows;
using WPF.Bill;
using WPF.Core;
using WPF.Core.Services;
using WPF.NoteBook;
using WPF.ToDo;
using WPF.Zero.Services;
using WPF.Zero.ViewModels;
using WPF.Zero.Views;

namespace WPF.Zero
{
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void OnInitialized()
        {
            var dialog = Container.Resolve<IDialogService>();

            dialog.ShowDialog("HelloWorldView", callBack =>
            {
                dialog.ShowDialog("LoginView", callBack =>
                {
                    //对登录的结果进行判断,如果OK就进入系统，如果NG就关闭系统
                    if (callBack.Result == ButtonResult.No)
                    {
                        Environment.Exit(0);
                    }
                });
            });
            base.OnInitialized();
        }

        protected override void RegisterTypes(IContainerRegistry services)
        {
            services.RegisterSingleton<IAppMapper, AppMapper>();

            services.RegisterDialog<HelloWorldView, HelloViewModel>();
            services.RegisterForNavigation<MainView, MainViewModel>();
            services.RegisterForNavigation<SettingView, SettingViewModel>();

            //数据库服务
            services.Register<BillService>();
            services.Register<IToDoService, ToDoService>();
            services.Register<INoteBookService, NoteBookService>();
            services.Register<IBillService, BillService>();
            services.Register<NoteBookService>();
            services.Register<UserService>();

            //登录弹窗
            services.RegisterDialog<LoginView, LoginViewModel>();
            //用户注册
            services.RegisterDialog<RegisterView, RegisterViewModel>();

            services.RegisterSingleton<INavigationMenuService, NavigationMenuService>();

            services.Register<IDialogWindow, DefaultDialogWindow>(); //default dialog host
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<BillModule>(); //账单模块
            moduleCatalog.AddModule<ToDoModule>(); //待办模块
            moduleCatalog.AddModule<NoteBookModule>(); //记事本模块
            base.ConfigureModuleCatalog(moduleCatalog);
        }
    }
}
